<?php

class Attendance extends Controller {

    function Attendance() {
        parent::Controller();
        $this->load->model('mod_attendance');
    }

    //========================function for load page muster==========================//

    function index() {
        $this->load->view('master');
    }

    //=============================this is function using view pagination==================//

    function manager() {
        if ($this->check_session()) {
            $get_attendance['value_attendance'] = $this->mod_attendance->select_view();
            $this->load->view('master', $get_attendance);
            $data['title'] = ' attendance manager';
        } else {
            redirect('admin/');
            exit();
        }
    }

    //=====================this is function for loading adding and insert data in to database========================//


    function add() {
        if ($this->check_session()) {
            if ($this->input->post('btn_submit')) {
                $this->form_validation->set_rules('class_name', 'classtime', 'required|trim|max_length[30]');
                $this->form_validation->set_rules('txtdate', 'datetime', 'required|trim|max_length[30]');
                $this->form_validation->set_rules('txtdate', 'datetime', 'required|trim|max_length[30]');
                $this->form_validation->set_rules('txtdrop', 'time', 'required|trim|max_length[30]');

                if ($this->form_validation->run() == FALSE) {
                    //$this->session->set_userdata('message','<p style="color:red; text-align:center;">field is required</p>');

                    $this->load->view('master');
                } else {
                    $this->mod_attendance->add();
                    $this->session->set_userdata('attendance_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Add Successful!</li></ul></dd></dl>');
                    redirect('attendance/manager');
                }
            } else {
                $this->load->view('attendance/add');
            }
        } else {
            redirect('admin/');
            exit();
        }
    }

    //===============================this is function for using editation of attendance===============================//


    function edit() {
        if ($this->check_session()) {
            if ($this->input->post('btn_submit')) {
                $this->mod_attendance->edit();
                $this->session->set_userdata('editattendance_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Edited Successful!</li></ul></dd></dl>');
                redirect('attendance/manager');
            } else {
                $edit['edit'] = $this->mod_attendance->select_edit();
                $this->load->view('master', $edit);
            }
        } else {
            redirect('admin/');
            exit();
        }
    }

    //==========================this function for using delect attendance=========================//


    function delete() {
        if ($this->check_session()) {
            $this->mod_attendance->delete();
            $this->session->set_userdata('deleteattendance_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Deleted Successful!</li></ul></dd></dl>');
            redirect('attendance/manager');
        } else {
            redirect('admin/');
            exit();
        }
    }

    //========this is function for using checking session=============

    public function check_session() {
        if ($this->session->userdata('use_username')) {
            return true;
        } else {
            return false;
        }
    }

}